package br.inf.solutions.apresentacoes.ssp.model;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.vexillum.model.CommonEntityActivated;
import br.com.vexillum.model.annotations.SearchField;
import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;

@SuppressWarnings("serial")
@ValidatorClass(validatorClass = "br.inf.solutions.apresentacoes.ssp.control.validator.ProviderValidator")
@Entity
@Table(name = "provider")
public class Provider extends CommonEntityActivated {

	@ManyToOne(fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.MERGE})
	@JoinColumn(name = "address_id", updatable = true, unique = false)
	private Address address;
	
	@SearchField
	@Validate(notNull = true)
	@Column(name = "cnpj", unique = false, updatable = true, insertable=true)
	private String cnpj;

	@Validate(notNull = true)
	@Column(name = "stateRegistration", unique = false, updatable = true)
	private String stateRegistration;

	@SearchField
	@Validate(notNull = true)
	@Column(name = "fantasyName", unique = false, updatable = true)
	private String fantasyName;

	@Validate(notNull = true)
	@Column(name = "companyName", unique = false, updatable = true)
	private String companyName;
	
	@Validate(notNull = true)
	@Column(name = "phone", unique = false, updatable = true)
	private String phone;
	
	public Provider() {
		address = new Address();
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public String getCnpj() {
		return cnpj;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}

	public String getStateRegistration() {
		return stateRegistration;
	}

	public void setStateRegistration(String stateRegistration) {
		this.stateRegistration = stateRegistration;
	}

	public String getFantasyName() {
		return fantasyName;
	}

	public void setFantasyName(String fantasyName) {
		this.fantasyName = fantasyName;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	@Override
	public String toString() {
		return getFantasyName();
	}
}